package com.guanghua.brick.db;

import java.util.ArrayList;
import java.util.List;

/**
 * 帮助进行?传参的sql查询
 * @author Administrator
 *
 */
public class SQLParamHelper {
	
	private StringBuffer sql = null;
	private List<Object> params = new ArrayList<Object>();
	
	private SQLParamHelper(String sql) {
		this.sql = new StringBuffer(sql);
	}
	
	public static SQLParamHelper newInstance(String sql) {
		return new SQLParamHelper(sql);
	}
	
	public SQLParamHelper appendSQLSection(String section, Object param) {
		if (param != null) {
			this.sql.append(section);
			params.add(param);
		}
		return this;
	}

	public List<Object> getParams() {
		return params;
	}

	public String getSql() {
		return sql.toString();
	}
	
	/**
	 * 如果param为null，这段section将不能添加
	 * @param section
	 * @param param
	 * @return
	 */
	public static String appendSQLSectionByString(String section, Object param) {
		if (param == null) return "";
		else return section;
	}
}
